package com.msmall.community.admin.action;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantUrl;
import com.msmall.community.bbs.model.Board;
import com.msmall.community.bbs.service.BoardManager;
import com.msmall.community.bbs.service.MasterManager;

public class BbsBoardAction extends HTMLBaseAction {

	private static final long serialVersionUID = 622429164723175438L;
	
	private Long boardId;
	
	private Long masterId;
	
	private Board board;
	
	private MasterManager masterManager;

	private BoardManager boardManager;
	
	public String index(){
		page.setClazz(Board.class);
		page.setOrderBy("parentId, orders");
		page.setOrder("asc,asc");
		page.setPageSize(10);
		boardManager.getPagination(page);
		page.setUrl(ConstantUrl.ADMIN_BOARD_INDEX);
		return "index";
	}
	
	public String create(){
		boardId = null;
		board = null;
		return "create";
	}
	public String update(){
		board = (Board) boardManager.get(Board.class, boardId);
		return "create";
	}

	public String save(){
		if(board.getAudit() == null){
			board.setAudit((short)0);
		}
		if(board.getEnabled() == null){
			board.setEnabled((short)0);
		}
		boardManager.saveBoard(board);
		return "save";
	}

	public Long getBoardId() {
		return boardId;
	}

	public void setBoardId(Long boardId) {
		this.boardId = boardId;
	}

	public Long getMasterId() {
		return masterId;
	}

	public void setMasterId(Long masterId) {
		this.masterId = masterId;
	}

	public Board getBoard() {
		return board;
	}

	public void setBoard(Board board) {
		this.board = board;
	}

	public void setMasterManager(MasterManager masterManager) {
		this.masterManager = masterManager;
	}

	public void setBoardManager(BoardManager boardManager) {
		this.boardManager = boardManager;
	}
}
